package br.com.fpf.pontoapp.model.dao.impl;

import android.content.ContentValues;
import android.database.Cursor;
import br.com.fpf.pontoapp.model.dao.IUserDAO;
import br.com.fpf.pontoapp.model.db.impl.Table;
import br.com.fpf.pontoapp.model.entity.User;

public class UserDAO extends AbstractDAO<User> implements IUserDAO {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public UserDAO() {
		super(Table.USER.getName());
	}

	@Override
	protected User cursorToObject(Cursor cursor) {
		User user = new User();

		int column = cursor.getColumnIndex(User.ID_COLUMN);
		if (column > 0) {
			user.setId(cursor.getLong(column));
		}

		column = cursor.getColumnIndex(User.USER_NAME);
		if (column > 0) {
			user.setUserName(cursor.getString(column));
		}

		column = cursor.getColumnIndex(User.REGISTRATION);
		if (column > 0) {
			user.setRegistration(cursor.getString(column));
		}

		column = cursor.getColumnIndex(User.LAST_MONTH_UPDATE);
		if (column > 0) {
			user.setLastMonthUpdate(cursor.getString(column));
		}

		column = cursor.getColumnIndex(User.LAST_BANK_HOURS);
		if (column > 0) {
			user.setLastBankHours(cursor.getInt(column));
		}

		return user;
	}

	@Override
	protected ContentValues objectToContentValues(User entity) {

		final ContentValues values = new ContentValues();

		if (entity.getUserName() != null) {
			values.put(User.USER_NAME, entity.getUserName());
		}

		if (entity.getRegistration() != null) {
			values.put(User.REGISTRATION, entity.getRegistration());
		}

		if (entity.getLastMonthUpdate() != null) {
			values.put(User.LAST_MONTH_UPDATE, entity.getLastMonthUpdate());
		}

		if (entity.getLastMonthUpdate() != null) {
			values.put(User.LAST_MONTH_UPDATE, entity.getLastMonthUpdate());
		}

		return values;
	}

}
